package com.jwsoft.manager.core.integration.individuation.helper;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.jwsoft.manager.common.enums.EnrollStatusFormalEnum;
import com.jwsoft.manager.common.enums.VerificationTypeEnum;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.eduBreakThrough.EduBreakThroughCreateVO;
import com.jwsoft.manager.common.vo.eduSchool.SchoolDistrictQueryVO;
import com.jwsoft.manager.common.vo.eduSchool.SchoolDistrictVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.HouseSchoolVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.HouseholdSchoolVO;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.BatchCallSjgxIntegration;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 金华生成预报名工具类
 * **/
@Component
public class JhEnrollBeforeCreateHelper {
    @Autowired
    EduStudentEnrollBeforeService eduStudentEnrollBeforeService;
    @Autowired
    private EduHouseholdService eduHouseholdService;
    @Autowired
    private EduAddressSchoolService eduAddressSchoolService;
    @Autowired
    private EduAddressService eduAddressService;
    @Autowired
    private EduHouseService eduHouseService;

    @Autowired
    private EduAppointStudentService eduAppointStudentService;
    @Autowired
    CommonIntegration commonIntegration;
    @Autowired
    private EduStudentEnrollService eduStudentEnrollService;
    @Autowired
    private EduSchoolBbService eduSchoolBbService;
    @Autowired
    private EduStudentEnrollFamilyService eduStudentEnrollFamilyService;
    @Autowired
    private EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    private EduBreakThroughService eduBreakThroughService;
    @Autowired
    private EduSchoolVacancyService eduSchoolVacancyService;
    @Autowired
    private BatchCallSjgxIntegration batchCallSjgxIntegration;
    private final static String areaCode="330700";
    private final static String jthStr = "非亲属,其他非亲属,侄子,外甥女,外甥,侄女,小集体户主,其他,曾孙女或外曾孙女,曾孙子或外曾孙子,其他孙子、孙女、外孙子、外孙女,堂兄弟、堂姐妹";
    /**
     * 单个预采集数据生成预报名
     * **/
    @Transactional
    public int createEnrollBefore(EduStudentEnrollPre eduStudentEnrollPre){
        String studentEnrollPreId=eduStudentEnrollPre.getStudentEnrollPreId();
        if(StringUtils.isBlank(studentEnrollPreId)){
            throw new AppException("预采集id不能为空");
        }
        List<String> enrollStatusList=new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper=new QueryWrapper<>();
        enrollQueryWrapper.lambda().eq(EduStudentEnroll::getIdcard,eduStudentEnrollPre.getIdcard())
                .in(EduStudentEnroll::getEnrollStatus,enrollStatusList)
                .eq(EduStudentEnroll::getYear,eduStudentEnrollPre.getYear());
        if(eduStudentEnrollService.count(enrollQueryWrapper)>0){
            throw new AppException("该学生已报名，不能重复生成");
        }
        //查询是否存在预报名数据,不是特殊人员的可以重新生成，特殊人员只能手动删除
        QueryWrapper<EduStudentEnrollBefore> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().select(EduStudentEnrollBefore::getEnrollBeforeId).eq(EduStudentEnrollBefore::getStudentEnrollPreId,studentEnrollPreId)
                .eq(EduStudentEnrollBefore::getSpecialFlag, BoolEnum.FALSE.getType());
        List<EduStudentEnrollBefore> oldBeforeList=eduStudentEnrollBeforeService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(oldBeforeList)){
            List<Long> oldIdList=oldBeforeList.stream().map(EduStudentEnrollBefore::getEnrollBeforeId).collect(Collectors.toList());
            eduStudentEnrollBeforeService.removeByIds(oldIdList);
        }
        //获取招生年度
        int year=eduStudentEnrollPre.getYear();
        //获取招生配置参数
        EduOperationCacheQueryVO queryVO=new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        queryVO.setAreaCode(eduStudentEnrollPre.getAreaCode());
        queryVO.setYear(year);
        EduOperationCacheVO eduOperationCacheVO=eduSystemConfigIntegration.getEduOperation(queryVO);
        if(eduOperationCacheVO==null){
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        Map<String, EduOperationCacheDetailVO> operation=eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO fcOperation=operation.get("YW024");
        if(fcOperation==null||fcOperation.getEndTime()==null){
            throw new AppException(year+"年度义务教育阶段招生参数未配置房产有效截止时间");
        }
        EduOperationCacheDetailVO hjOperation=operation.get("YW025");
        if(hjOperation==null||hjOperation.getEndTime()==null){
            throw new AppException(year+"年度义务教育阶段招生参数未配置户籍有效截止时间");
        }
        if(BoolEnum.FALSE.getType().equalsIgnoreCase(eduStudentEnrollPre.getConsistentFlag())){
            //房户一致未处理，先调用房户一致处理方法
            batchCallSjgxIntegration.fhyzTaskDg(eduStudentEnrollPre);
        }
        List<EduStudentEnrollBefore> list=compare(eduStudentEnrollPre,operation);
        //判断是否补报（第二轮报名），补报需要清除,只要过了家长报名时间，就按补报处理
        long curTime = DateUtil.currentSeconds();
        EduOperationCacheDetailVO bmOperation=operation.get("YW002");

        if(bmOperation!=null&&bmOperation.getEndTime()!=null){
            Date applyEndDate=bmOperation.getEndTime();
            if(applyEndDate.getTime()/1000-curTime<0){
                ArrayList<String> areaCodeList = new ArrayList<>();//全部区域
                areaCodeList.add("330700");
                areaCodeList.add("330701");
                areaCodeList.add("330702");
                areaCodeList.add("330703");
                areaCodeList.add("330704");
                QueryWrapper<EduSchoolBb> bbQueryWrapper=new QueryWrapper<>();
                bbQueryWrapper.lambda().select(EduSchoolBb::getSchoolId).eq(EduSchoolBb::getYear,eduStudentEnrollPre.getYear())
                .in(EduSchoolBb::getAreaCode,areaCodeList);//修改成全部区域
                List<EduSchoolBb> bbList=eduSchoolBbService.list(bbQueryWrapper);
                if(!CollectionUtils.isEmpty(bbList)){
                    List<String> schoolList=bbList.stream().map(EduSchoolBb::getSchoolId).distinct().collect(Collectors.toList());
                    List<EduStudentEnrollBefore> retList=new ArrayList<>();
                    for(EduStudentEnrollBefore before:list){
                        if(schoolList.contains(before.getSchoolId())){
                            retList.add(before);
                        }
                    }
                    list=retList;
                }else{
                    return 0;
                }
            }
        }

        //判断是否第三轮报名,补报结束之后才能进行第三轮生成
        EduOperationCacheDetailVO bbOperation=operation.get("YW022");
        //第二批第二轮
        EduOperationCacheDetailVO bbTwoOperation=operation.get("YW072");
        if(bbOperation!=null&&bbOperation.getEndTime()!=null){
            Date applyEndDate=bbOperation.getEndTime();
            if(applyEndDate.getTime()/1000-curTime<0){
                boolean qbFlag=true;
                if(bbTwoOperation!=null&&bbTwoOperation.getEndTime()!=null){
                    Date applyEndTwoDate=bbTwoOperation.getEndTime();
                    if(applyEndTwoDate.getTime()/1000-curTime<0){
                        qbFlag=true;
                    }else{
                        qbFlag=false;
                    }
                }
                if (qbFlag) {
                    ArrayList<String> areaCodeList = new ArrayList<>();//全部区域
                    areaCodeList.add("330700");
                    areaCodeList.add("330701");
                    areaCodeList.add("330702");
                    areaCodeList.add("330703");
                    areaCodeList.add("330704");
                    QueryWrapper<EduSchoolVacancy> qbQueryWrapper = new QueryWrapper<>();
                    qbQueryWrapper.lambda().select(EduSchoolVacancy::getSchoolId).eq(EduSchoolVacancy::getYear, eduStudentEnrollPre.getYear())
                            .in(EduSchoolVacancy::getAreaCode, areaCodeList);//修改成全部区域
                    List<EduSchoolVacancy> qbList = eduSchoolVacancyService.list(qbQueryWrapper);
                    if (!CollectionUtils.isEmpty(qbList)) {
                        List<String> schoolList = qbList.stream().map(EduSchoolVacancy::getSchoolId).distinct().collect(Collectors.toList());
                        List<EduStudentEnrollBefore> retList = new ArrayList<>();
                        for (EduStudentEnrollBefore before : list) {
                            if (schoolList.contains(before.getSchoolId())) {
                                retList.add(before);
                            }
                        }
                        list = retList;
                    } else {
                        return 0;
                    }
                }
            }
        }
        if(!CollectionUtils.isEmpty(list)){
            eduStudentEnrollBeforeService.saveBatch(list);
            return list.size();
        }
        return 0;
    }
    //比对
    private List<EduStudentEnrollBefore> compare(EduStudentEnrollPre eduStudentEnrollPre, Map<String, EduOperationCacheDetailVO> operation){
        List<EduStudentEnrollBefore> list=new ArrayList<>();
        //获取房产学校
        List<HouseSchoolVO> houseSchoolVOList=this.getHouseSchool(eduStudentEnrollPre,operation);
        //获取户籍学校
        List<HouseholdSchoolVO> householdSchoolVOList=this.getHouseholdSchool(eduStudentEnrollPre,operation);
        //特殊户口
        List<String> jthList = Arrays.stream(jthStr.split(",")).map(s -> s).collect(Collectors.toList());
        //已生成的学校和类别
        Map<String,String> schoolMap=new HashMap<>();
        //已生成的房产
        Map<String,String> houseMap=new HashMap<>();
        //生成学校ABC类别

        //有户及有户有房
        for(HouseholdSchoolVO householdSchoolVO:householdSchoolVOList){

            EduStudentEnrollBefore eduStudentEnrollBefore=new EduStudentEnrollBefore();
            eduStudentEnrollBefore.setHouseholdId(householdSchoolVO.getHouseholdId());
            eduStudentEnrollBefore.setHouseholdAdress(householdSchoolVO.getAddress());
            eduStudentEnrollBefore.setAuthStatus(AuthStatusEnum.YES.getType());
            eduStudentEnrollBefore.setAuthRemarks("系统大数据比对，学校关联的户籍");
            eduStudentEnrollBefore.setCreateName("金华新生报名系统");
            eduStudentEnrollBefore.setAreaCode(householdSchoolVO.getAreaCode());
            eduStudentEnrollBefore.setSchoolId(householdSchoolVO.getSchoolId());
            eduStudentEnrollBefore.setYear(eduStudentEnrollPre.getYear());
            eduStudentEnrollBefore.setStudentEnrollPreId(eduStudentEnrollPre.getStudentEnrollPreId());
            eduStudentEnrollBefore.setConfigName("B");//有户籍默认是B
            eduStudentEnrollBefore.setConfigNameNum(201);
            eduStudentEnrollBefore.setConfigNameAlias("有户无房");
            eduStudentEnrollBefore.setAborigineFlag(householdSchoolVO.getNativeFlag()==null?BoolEnum.FALSE.getType():householdSchoolVO.getNativeFlag());
            eduStudentEnrollBefore.setServiceFlag(householdSchoolVO.getServiceAreaFlag()==null?BoolEnum.FALSE.getType():householdSchoolVO.getServiceAreaFlag());
            eduStudentEnrollBefore.setPrivateAppointFlag(BoolEnum.FALSE.getType());
            eduStudentEnrollBefore.setAppointFlag(BoolEnum.FALSE.getType());
            eduStudentEnrollBefore.setSpecialFlag(BoolEnum.FALSE.getType());
            if("集体户".equalsIgnoreCase(householdSchoolVO.getAccountType())
                    ||(StringUtils.isNotBlank(householdSchoolVO.getRelation())
                    && jthList.contains(householdSchoolVO.getRelation()))) {
                //如果是集体户或者挂靠户
                eduStudentEnrollBefore.setConfigName("特殊户口");
                eduStudentEnrollBefore.setConfigNameAlias("集体户、挂靠户等");
                eduStudentEnrollBefore.setConfigNameNum(401);
                eduStudentEnrollBefore.setAuthRemarks("系统大数据比对，集体户或挂靠户");
            }
            //判断判断房户是否一致，一致的情况下升到A
            boolean bdFlag=false;
            if("B".equalsIgnoreCase(eduStudentEnrollBefore.getConfigName())&&BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollPre.getConsistentFlag())){
                if(householdSchoolVO.getHouseholdId().equalsIgnoreCase(eduStudentEnrollPre.getHouseholdId())){
                    if("1".equals(eduStudentEnrollPre.getConsistentType())){
                        //大数据比对
                        for(HouseSchoolVO houseSchoolVO:houseSchoolVOList){
                            if(houseSchoolVO.getHouseId().equalsIgnoreCase(eduStudentEnrollPre.getHouseId())&&householdSchoolVO.getSchoolId().equalsIgnoreCase(houseSchoolVO.getSchoolId())){
                                //大数据房产一致比对，必须户籍的地址和房产的地址同一个学校关联了才行
                                eduStudentEnrollBefore.setConfigName("A");//有房有户升级到A
                                eduStudentEnrollBefore.setHouseAdreess(houseSchoolVO.getAddress());
                                eduStudentEnrollBefore.setHouseId(houseSchoolVO.getHouseId());
                                eduStudentEnrollBefore.setHouseAdreess(houseSchoolVO.getAddress());
                                eduStudentEnrollBefore.setServiceFlag(householdSchoolVO.getServiceAreaFlag());
                                eduStudentEnrollBefore.setConfigNameNum(101);
                                eduStudentEnrollBefore.setConfigNameAlias("房户一致（正学区）");
                                if(!schoolMap.containsKey(householdSchoolVO.getSchoolId())){
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getAborigineFlag())&&!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getServiceFlag())){
                                        eduStudentEnrollBefore.setConfigNameAlias("房户一致（原住民）");
                                        eduStudentEnrollBefore.setConfigNameNum(102);
                                    }else if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getAborigineFlag())&&BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getServiceFlag())){
                                        //如果地址是服务区，则房户一致按服务区处理
                                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getServiceFlag())){
                                            eduStudentEnrollBefore.setConfigNameAlias("房户一致（服务区）");
                                            eduStudentEnrollBefore.setConfigNameNum(204);
                                        }
                                    }else if(BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getAborigineFlag())&&BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getServiceFlag())){
                                        //如果地址是服务区，则房户一致按服务区处理
                                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getServiceFlag())){
                                            eduStudentEnrollBefore.setConfigNameAlias("房户一致（服务区原住民）");
                                            eduStudentEnrollBefore.setConfigNameNum(205);
                                        }
                                    }
                                    schoolMap.put(householdSchoolVO.getSchoolId(),eduStudentEnrollBefore.getConfigName());
                                    houseMap.put(houseSchoolVO.getHouseId(),houseSchoolVO.getRealProperty());
                                    //设置需要线下核验的类型
                                    String hyType="";
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getOfflineFlag())){
                                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())){
                                            hyType= VerificationTypeEnum.fwqhj.getType();
                                        }else{
                                            hyType=VerificationTypeEnum.hj.getType();
                                        }

                                    }
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getVerificationFlag())){
                                        if(StringUtils.isNotBlank(hyType)){
                                            hyType= hyType+","+VerificationTypeEnum.hjdz.getType();
                                        }else{
                                            hyType=hyType+VerificationTypeEnum.hjdz.getType();
                                        }

                                    }
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getOfflineFlag())){

                                        if(StringUtils.isNotBlank(hyType)){
                                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                                                hyType= hyType+","+VerificationTypeEnum.fwqfc.getType();
                                            }else{
                                                hyType=hyType+","+VerificationTypeEnum.fc.getType();
                                            }
                                        }else{
                                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                                                hyType= hyType+VerificationTypeEnum.fwqfc.getType();
                                            }else{
                                                hyType=hyType+VerificationTypeEnum.fc.getType();
                                            }
                                        }

                                    }
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getFcblFlag())){
                                        if(StringUtils.isNotBlank(hyType)){
                                            hyType=hyType+","+VerificationTypeEnum.fcbl.getType();
                                        }else{
                                            hyType=VerificationTypeEnum.fcbl.getType();
                                        }
                                    }
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getVerificationFlag())){
                                        if(StringUtils.isNotBlank(hyType)){
                                            hyType= hyType+","+VerificationTypeEnum.fcdz.getType();
                                        }else{
                                            hyType=hyType+VerificationTypeEnum.fcdz.getType();
                                        }

                                    }
                                    eduStudentEnrollBefore.setVerificationType(hyType);
                                    list.add(eduStudentEnrollBefore);
                                    bdFlag=true;
                                    break;
                                }

                            }
                        }
                    }else{
                        //人工确认房户一致
                        eduStudentEnrollBefore.setConfigName("A");//有房有户升级到A
                        eduStudentEnrollBefore.setAborigineFlag(eduStudentEnrollPre.getAborigineFlag());
                        eduStudentEnrollBefore.setServiceFlag(eduStudentEnrollPre.getServiceAreaFlag());
                        HouseSchoolVO houseVO=null;
                        if(StringUtils.isBlank(eduStudentEnrollPre.getHouseId())){
                            //原住民等房产为空，设置房产地址为 户籍地址
                            eduStudentEnrollBefore.setHouseAdreess(householdSchoolVO.getAddress());
                        }else{
                            eduStudentEnrollBefore.setHouseId(eduStudentEnrollPre.getHouseId());
                            for(HouseSchoolVO houseSchoolVO:houseSchoolVOList){
                                if(houseSchoolVO.getHouseId().equalsIgnoreCase(eduStudentEnrollPre.getHouseId())&&householdSchoolVO.getSchoolId().equalsIgnoreCase(houseSchoolVO.getSchoolId())){
                                    //人工确认房户一致，需要再次比对房产和户籍地址所在学区是否一致
                                    eduStudentEnrollBefore.setHouseAdreess(houseSchoolVO.getAddress());
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getFcblFlag())){

                                        eduStudentEnrollBefore.setVerificationType(VerificationTypeEnum.fcbl.getType());
                                    }
                                    houseVO=houseSchoolVO;
                                    houseMap.put(houseSchoolVO.getHouseId(), houseSchoolVO.getRealProperty());

                                    break;

                                }
                            }
                        }
                        eduStudentEnrollBefore.setConfigNameNum(101);
                        eduStudentEnrollBefore.setConfigNameAlias("房户一致（正学区）");
                        if(!schoolMap.containsKey(householdSchoolVO.getSchoolId())) {

                            if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getAborigineFlag())&&!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getServiceFlag())) {
                                eduStudentEnrollBefore.setConfigNameAlias("房户一致（原住民）");
                                eduStudentEnrollBefore.setConfigNameNum(102);
                            } else if (!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getAborigineFlag())&&BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getServiceFlag())) {
                                eduStudentEnrollBefore.setConfigNameAlias("房户一致（服务区）");
                                eduStudentEnrollBefore.setConfigNameNum(103);
                            }else if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getAborigineFlag())&&BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollBefore.getServiceFlag())) {
                                eduStudentEnrollBefore.setConfigNameAlias("房户一致（服务区原住民）");
                                eduStudentEnrollBefore.setConfigNameNum(104);
                            }
                            //人工核验房户一致的不需要线下核验的类型

                            schoolMap.put(householdSchoolVO.getSchoolId(), eduStudentEnrollBefore.getConfigName());
                            list.add(eduStudentEnrollBefore);
                            bdFlag = true;

                        }

                    }

                }
            }

            if("B".equalsIgnoreCase(eduStudentEnrollBefore.getConfigName())){
                if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getNativeFlag())
                        ||BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollPre.getAborigineFlag())){
                    //地址是原住居民可读或者人是原住居民
                    if(!schoolMap.containsKey(householdSchoolVO.getSchoolId())){
                        //该学生是原住居民
                        eduStudentEnrollBefore.setConfigName("A");//原住居民升级到A
                        schoolMap.put(householdSchoolVO.getSchoolId(),eduStudentEnrollBefore.getConfigName());
                        eduStudentEnrollBefore.setConfigNameAlias("房户一致（原住民）");
                        eduStudentEnrollBefore.setConfigNameNum(102);
                        if("2".equals(eduStudentEnrollPre.getConsistentType())&&StringUtils.isNotBlank(eduStudentEnrollPre.getAborigineFlag())){
                            eduStudentEnrollBefore.setAborigineFlag(eduStudentEnrollPre.getAborigineFlag());
                        }else{
                            eduStudentEnrollBefore.setAborigineFlag(householdSchoolVO.getNativeFlag()==null?BoolEnum.FALSE.getType():householdSchoolVO.getNativeFlag());
                        }
                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())||BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollPre.getServiceAreaFlag())){
                            eduStudentEnrollBefore.setConfigNameAlias("房户一致（服务区原住民）");
                            eduStudentEnrollBefore.setConfigNameNum(104);
                        }
                        //设置需要线下核验的类型
                        String hyType="";
                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getOfflineFlag())){
                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())){
                                hyType= VerificationTypeEnum.fwqhj.getType()+","+VerificationTypeEnum.fwqfc.getType();
                            }else{
                                hyType=VerificationTypeEnum.hj.getType()+","+VerificationTypeEnum.fc.getType();
                            }

                        }
                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getVerificationFlag())){
                            if(StringUtils.isNotBlank(hyType)){
                                hyType= hyType+","+VerificationTypeEnum.hjdz.getType();
                            }else{
                                hyType=hyType+VerificationTypeEnum.hjdz.getType();
                            }
                        }
                        eduStudentEnrollBefore.setVerificationType(hyType);
                        list.add(eduStudentEnrollBefore);
                        bdFlag=true;
                    }
                }else{
                    if(!schoolMap.containsKey(householdSchoolVO.getSchoolId())){
                        //其他的按B处理
                        schoolMap.put(householdSchoolVO.getSchoolId(),eduStudentEnrollBefore.getConfigName());
                        //设置需要线下核验的类型
                        String hyType="";
                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getOfflineFlag())){
                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())){
                                hyType= VerificationTypeEnum.fwqhj.getType();
                            }else{
                                hyType=VerificationTypeEnum.hj.getType();
                            }

                        }
                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getVerificationFlag())){
                            if(StringUtils.isNotBlank(hyType)){
                                hyType= hyType+","+VerificationTypeEnum.hjdz.getType();
                            }else{
                                hyType=hyType+VerificationTypeEnum.hjdz.getType();
                            }
                        }
                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())){
                            eduStudentEnrollBefore.setConfigNameNum(202);
                            eduStudentEnrollBefore.setConfigNameAlias("有户无房（服务区）");
                        }
                        List<String> idcardList = new ArrayList<>();
                        if (StringUtils.isNotBlank(eduStudentEnrollPre.getIdcard())) {
                            idcardList.add(eduStudentEnrollPre.getIdcard());
                        }
                        if (StringUtils.isNotBlank(eduStudentEnrollPre.getFatherIdcard())) {
                            idcardList.add(eduStudentEnrollPre.getFatherIdcard());
                        }
                        if (StringUtils.isNotBlank(eduStudentEnrollPre.getMotherIdcard())) {
                            idcardList.add(eduStudentEnrollPre.getMotherIdcard());
                        }
                        //有户无房，需要在市区范围内没有房产
                        boolean hasHouse=false;
                        List<EduHouse> houseList = eduHouseService.getHouseByAllIdcard(idcardList, eduStudentEnrollPre.getYear(), "1", null);
                        if (!CollectionUtils.isEmpty(houseList)){

                            for(EduHouse eduHouseVO:houseList) {
                                if (StringUtils.isBlank(eduHouseVO.getPrimarySchoolOne())) {
                                    hasHouse = true;
                                } else {
                                    Double p = Double.parseDouble(eduHouseVO.getPrimarySchoolOne().replaceAll("%", ""));
                                    if (p > 50) {
                                        hasHouse = true;
                                    }
                                }
                            }
                        }
                        if(hasHouse){
                            //可以报名，但需要核验
                            if(StringUtils.isNotBlank(hyType)){
                                hyType= hyType+","+VerificationTypeEnum.yhwfsqnyf.getType();
                            }else{
                                hyType=hyType+VerificationTypeEnum.yhwfsqnyf.getType();
                            }
                        }
                        eduStudentEnrollBefore.setVerificationType(hyType);

                        list.add(eduStudentEnrollBefore);
                        bdFlag = true;


                    }
                }
            }
            if(bdFlag){
                //房户一致比对成功后，户籍相关后续不在处理
                continue;
            }

            boolean flag=true;
            for(HouseSchoolVO houseSchoolVO:houseSchoolVOList){
                if(houseSchoolVO.getSchoolId().equals(householdSchoolVO.getSchoolId())&&!BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                    //无户的服务区不处理
                    EduStudentEnrollBefore aBefore=new EduStudentEnrollBefore();
                    BeanUtil.copyProperties(eduStudentEnrollBefore,aBefore);
                    if(eduStudentEnrollBefore.getConfigName().equalsIgnoreCase("特殊户口")){
                        aBefore.setConfigName("C");//特殊户口按房产处理升到C
                        aBefore.setHouseId(houseSchoolVO.getHouseId());
                        aBefore.setHouseAdreess(houseSchoolVO.getAddress());
                        if(!schoolMap.containsKey(householdSchoolVO.getSchoolId())){
                            schoolMap.put(householdSchoolVO.getSchoolId(),aBefore.getConfigName());
                            houseMap.put(houseSchoolVO.getHouseId(),houseSchoolVO.getRealProperty());
                            aBefore.setConfigNameAlias("有房无户");
                            aBefore.setConfigNameNum(301);
                            //设置需要线下核验的类型
                            String hyType="";
                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getOfflineFlag())){
                                if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                                    hyType= VerificationTypeEnum.fwqfc.getType();
                                }else{
                                    hyType=VerificationTypeEnum.fc.getType();
                                }

                            }
                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getVerificationFlag())){
                                if(StringUtils.isNotBlank(hyType)){
                                    hyType= hyType+","+VerificationTypeEnum.fcdz.getType();
                                }else{
                                    hyType=hyType+VerificationTypeEnum.fcdz.getType();
                                }
                            }
                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getFcblFlag())){
                                if(StringUtils.isNotBlank(hyType)){
                                    hyType=hyType+","+VerificationTypeEnum.fcbl.getType();
                                }else{
                                    hyType=VerificationTypeEnum.fcbl.getType();
                                }
                            }
                            eduStudentEnrollBefore.setVerificationType(hyType);
                            list.add(aBefore);
                            flag=false;
                        }
                    }

                    break;

                }
            }
            if(flag&&!BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())){
                //服务区只有户口的，不处理
                schoolMap.put(householdSchoolVO.getSchoolId(),eduStudentEnrollBefore.getConfigName());
                //设置需要线下核验的类型
                String hyType="";
                if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getOfflineFlag())){
                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())){
                        hyType= VerificationTypeEnum.fwqhj.getType();
                    }else{
                        hyType=VerificationTypeEnum.hj.getType();
                    }

                }
                if(BoolEnum.TRUE.getType().equalsIgnoreCase(householdSchoolVO.getVerificationFlag())){
                    if(StringUtils.isNotBlank(hyType)){
                        hyType= hyType+","+VerificationTypeEnum.hjdz.getType();
                    }else{
                        hyType=hyType+VerificationTypeEnum.hjdz.getType();
                    }
                }
                eduStudentEnrollBefore.setVerificationType(hyType);
                list.add(eduStudentEnrollBefore);
            }
        }
        //有房
        for(HouseSchoolVO houseSchoolVO:houseSchoolVOList){
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                //只有房产服务区学校不处理，服务区只能是房户一致
                continue;
            }
            //判断是否存在
            EduStudentEnrollBefore eduStudentEnrollBefore=new EduStudentEnrollBefore();
            eduStudentEnrollBefore.setHouseId(houseSchoolVO.getHouseId());
            eduStudentEnrollBefore.setHouseAdreess(houseSchoolVO.getAddress());
            eduStudentEnrollBefore.setAuthStatus(AuthStatusEnum.YES.getType());
            eduStudentEnrollBefore.setAuthRemarks("系统大数据比对，学校关联的房产");
            eduStudentEnrollBefore.setCreateName("金华新生报名系统");
            eduStudentEnrollBefore.setAreaCode(houseSchoolVO.getAreaCode());
            eduStudentEnrollBefore.setSchoolId(houseSchoolVO.getSchoolId());
            eduStudentEnrollBefore.setYear(eduStudentEnrollPre.getYear());
            eduStudentEnrollBefore.setStudentEnrollPreId(eduStudentEnrollPre.getStudentEnrollPreId());
            eduStudentEnrollBefore.setConfigName("C");//只有房默认是C
            eduStudentEnrollBefore.setPrivateAppointFlag(BoolEnum.FALSE.getType());
            eduStudentEnrollBefore.setAppointFlag(BoolEnum.FALSE.getType());
            eduStudentEnrollBefore.setSpecialFlag(BoolEnum.FALSE.getType());
            if(!schoolMap.containsKey(houseSchoolVO.getSchoolId())){
                schoolMap.put(eduStudentEnrollBefore.getSchoolId(),eduStudentEnrollBefore.getConfigName());
                houseMap.put(houseSchoolVO.getHouseId(),houseSchoolVO.getRealProperty());
                eduStudentEnrollBefore.setConfigNameAlias("有房无户");
                eduStudentEnrollBefore.setConfigNameNum(301);
                //设置需要线下核验的类型
                String hyType="";
                if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getOfflineFlag())){
                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                        hyType= VerificationTypeEnum.fwqfc.getType();
                    }else{
                        hyType=VerificationTypeEnum.fc.getType();
                    }

                }
                if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getVerificationFlag())){
                    if(StringUtils.isNotBlank(hyType)){
                        hyType= hyType+","+VerificationTypeEnum.fcdz.getType();
                    }else{
                        hyType=hyType+VerificationTypeEnum.fcdz.getType();
                    }
                }
                if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getFcblFlag())){
                    if(StringUtils.isNotBlank(hyType)){
                        hyType=hyType+","+VerificationTypeEnum.fcbl.getType();
                    }else{
                        hyType=VerificationTypeEnum.fcbl.getType();
                    }
                }
                eduStudentEnrollBefore.setVerificationType(hyType);
                list.add(eduStudentEnrollBefore);
            }else {
                if(schoolMap.get(houseSchoolVO.getSchoolId()).equals(eduStudentEnrollBefore.getConfigName())
                        &&!houseMap.containsKey(houseSchoolVO.getHouseId())&&!houseMap.containsValue(houseSchoolVO.getRealProperty())){
                    houseMap.put(houseSchoolVO.getHouseId(),houseSchoolVO.getRealProperty());
                    eduStudentEnrollBefore.setConfigNameAlias("有房无户");
                    eduStudentEnrollBefore.setConfigNameNum(301);
                    //设置需要线下核验的类型
                    String hyType="";
                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getOfflineFlag())){
                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                            hyType= VerificationTypeEnum.fwqfc.getType();
                        }else{
                            hyType=VerificationTypeEnum.fc.getType();
                        }

                    }
                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getVerificationFlag())){
                        if(StringUtils.isNotBlank(hyType)){
                            hyType= hyType+","+VerificationTypeEnum.fcdz.getType();
                        }else{
                            hyType=hyType+VerificationTypeEnum.fcdz.getType();
                        }
                    }
                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(houseSchoolVO.getFcblFlag())){
                        if(StringUtils.isNotBlank(hyType)){
                            hyType=hyType+","+VerificationTypeEnum.fcbl.getType();
                        }else{
                            hyType=VerificationTypeEnum.fcbl.getType();
                        }
                    }
                    eduStudentEnrollBefore.setVerificationType(hyType);
                    list.add(eduStudentEnrollBefore);
                }
            }
        }
        //突破学区处理
        List<EduStudentEnrollBefore> breakBeforeList = new ArrayList<>();
        for (EduStudentEnrollBefore before : list) {
            List<EduBreakThroughCreateVO> breakThroughCreateVOS = eduBreakThroughService.getMainSchoolBySchoolId(before.getSchoolId(), before.getYear());
            if (!CollectionUtils.isEmpty(breakThroughCreateVOS)) {
                for (EduBreakThroughCreateVO breakThroughCreateVO : breakThroughCreateVOS) {
                    if (StringUtils.isBlank(breakThroughCreateVO.getConfigNameList())) {
                        continue;
                    }
                    List<String> configNameList = Arrays.stream(breakThroughCreateVO.getConfigNameList().split(",")).map(s -> s).collect(Collectors.toList());
                    if (configNameList.contains(before.getConfigName())) {
                        EduStudentEnrollBefore eduStudentEnrollBefore = new EduStudentEnrollBefore();
                        BeanUtil.copyProperties(before, eduStudentEnrollBefore);
                        eduStudentEnrollBefore.setSchoolId(breakThroughCreateVO.getSchoolId());
                        eduStudentEnrollBefore.setAuthRemarks("系统设置，突破学区");
                        breakBeforeList.add(eduStudentEnrollBefore);
                    }

                }
            }
        }
        list.addAll(breakBeforeList);

        return list;
    }
    //获取房产信息所属学校
    public List<HouseSchoolVO> getHouseSchool(EduStudentEnrollPre eduStudentEnrollPre, Map<String, EduOperationCacheDetailVO> operation){
        List<HouseSchoolVO> retList=new ArrayList<>();
        //获取本人以及父母名下房产信息
        List<String> idcardList=new ArrayList<>();
        if(StringUtils.isNotBlank(eduStudentEnrollPre.getIdcard())){
            idcardList.add(eduStudentEnrollPre.getIdcard());
        }
        LambdaQueryWrapper<EduStudentEnrollFamily> familyLambdaQueryWrapper=new LambdaQueryWrapper<>();
        familyLambdaQueryWrapper.select(EduStudentEnrollFamily::getStudentPreFamilyId,EduStudentEnrollFamily::getCardType,EduStudentEnrollFamily::getIdcard).eq(EduStudentEnrollFamily::getStudentEnrollPreId,eduStudentEnrollPre.getStudentEnrollPreId())
                .eq(EduStudentEnrollFamily::getHouseFlag,BoolEnum.TRUE.getType());
        List<EduStudentEnrollFamily> familyList=eduStudentEnrollFamilyService.list(familyLambdaQueryWrapper);
        if(!CollectionUtils.isEmpty(familyList)){
            for(EduStudentEnrollFamily family:familyList){
                if(family!=null&&StringUtils.isNotBlank(family.getIdcard())){
                    idcardList.add(family.getIdcard());
                }

            }
        }

        List<EduHouse> list= eduHouseService.getHouseByAllIdcard(idcardList,eduStudentEnrollPre.getYear(),BoolEnum.TRUE.getType(),null);
        if (!CollectionUtils.isEmpty(list)){
            // 正学区房产启用是参数
            EduOperationCacheDetailVO fcOperation=operation.get("YW024");
            if(fcOperation.getEndTime()==null){
                throw new AppException("YW024房产截止时间不能为空");
            }

            Long houseEndTime=Long.parseLong(DateUtil.format(fcOperation.getEndTime(),"yyyyMMdd"));
            // 服务区房产启用是参数
            EduOperationCacheDetailVO fcfwOperation=operation.get("YW060");
            if (fcfwOperation.getEndTime() == null){
                throw new AppException("YW060服务区房产截止时间不能为空");
            }
            Long houseEndTimeFw=Long.parseLong(DateUtil.format(fcfwOperation.getEndTime(),"yyyyMMdd"));
            for(EduHouse eduHouse:list){
                if(!BoolEnum.TRUE.getType().equals(eduHouse.getUseQueryFlag())){
                    //3年锁定未比对的,房产不算
                    throw new AppException(100,"3年锁定未比对的");
                }
                if(BoolEnum.TRUE.getType().equals(eduHouse.getUseFlag())){
                    //3年内房产使用，不能就读
                    continue;
                }
                //获取房产地址关联的学校信息
                Boolean flag = true;
                String addressId=eduHouse.getAddressId();
                String address= Convert.toDBC(eduHouse.getAddress());
                if(StringUtils.isNotBlank(eduHouse.getAddressId())) {
                    EduAddress eduAddress = eduAddressService.getById(addressId);
                    if (eduAddress == null) {
                        flag = true;
                        addressId = "";
                    } else {
                        if (!eduAddress.getAddressName().equals(address)) {
                            flag = true;
                            addressId = "";
                        } else {
                            flag = false;

                        }
                    }
                }
                if (flag) {
                    QueryWrapper<EduAddress> eduAddressQueryWrapper = new QueryWrapper<>();
                    eduAddressQueryWrapper.lambda().eq(EduAddress::getAddressName, address);
                    List<EduAddress> addressList = eduAddressService.list(eduAddressQueryWrapper);
                    if (CollectionUtils.isEmpty(addressList)) {
                        throw new AppException("地址池中未找到该房产地址，请先联系管理员添加");
                    } else {
                        if (addressList.size() > 1) {
                            throw new AppException("同一房产地址在地址池中找到多条数据，请联系管理员处理");
                        }
                        addressId = addressList.get(0).getAddressId();
                    }
                }

                SchoolDistrictQueryVO queryVO=new SchoolDistrictQueryVO();
                queryVO.setSchoolCategory(eduStudentEnrollPre.getSchoolCategory());
                queryVO.setAddressId(addressId);
                List<SchoolDistrictVO> schoolList= eduAddressSchoolService.getSchoolInfo(queryVO);
                if (!CollectionUtils.isEmpty(schoolList)){
                    for(SchoolDistrictVO eduAddressSchool:schoolList){
                        boolean conFlag = false;
                        for (HouseSchoolVO houseSchoolVO : retList) {
                            if (eduAddressSchool.getAddressId().equalsIgnoreCase(houseSchoolVO.getAddressId()) && houseSchoolVO.getSchoolId().equalsIgnoreCase(eduAddressSchool.getOrgId())) {
                                conFlag = true;
                            }
                        }
                        if (conFlag) {
                            continue;
                        }
                        //判断启用时间是否小于参数设置时间
                        HouseSchoolVO vo = Convert.convert(HouseSchoolVO.class, eduHouse);
                        vo.setOfflineFlag(BoolEnum.FALSE.getType());
                        vo.setServiceAreaFlag(eduAddressSchool.getServiceAreaFlag());
                        if(StringUtils.isBlank(vo.getServiceAreaFlag())){
                            vo.setServiceAreaFlag(BoolEnum.FALSE.getType());
                        }
                        if(StringUtils.isBlank(eduAddressSchool.getNativeFlag())){
                            vo.setNativeFlag(BoolEnum.FALSE.getType());
                        }else{
                            vo.setNativeFlag(eduAddressSchool.getNativeFlag());
                        }

                        boolean addFlag=true;
                        if(!BoolEnum.TRUE.getType().equals(eduAddressSchool.getHouseEndTimeNo())){
                            if(eduHouse.getRegisterDate()!=null){
                                Long djTime=Long.parseLong(DateUtil.format(eduHouse.getRegisterDate(),"yyyyMMdd"));
                                if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceAreaFlag())){
                                    //服务区
                                    if(eduAddressSchool.getHouseEndTimeFw()!=null){

                                        Long endTime= Long.parseLong(DateUtil.format(eduAddressSchool.getHouseEndTimeFw(),"yyyyMMdd"));
                                        if(djTime>endTime){
                                            addFlag=false;
                                        }
                                    }else{
                                        if(djTime>houseEndTimeFw){
                                            addFlag=false;
                                        }
                                    }
                                }else{
                                    //正学区
                                    if(eduAddressSchool.getHouseEndTime()!=null){

                                        Long endTime=Long.parseLong(DateUtil.format(eduAddressSchool.getHouseEndTime(),"yyyyMMdd"));
                                        if(djTime>endTime){
                                            addFlag=false;
                                        }
                                    }else{
                                        if(djTime>houseEndTime){
                                            addFlag=false;
                                        }
                                    }
                                }
                            }else{
                                //不动产说房产时间为空都是16年6月份 之前的
                                //vo.setOfflineFlag(BoolEnum.TRUE.getType());
                            }

                        }

                        if(addFlag) {

                            if (AuthStatusEnum.NODO.getType().equalsIgnoreCase(eduHouse.getAuthStatus())){
                                //房产表示待审核的数据，需要上传核验材料
                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                            }
                            if (StringUtils.isNotBlank(eduHouse.getPrimarySchoolOne())) {
                                Double p = Double.parseDouble(eduHouse.getPrimarySchoolOne().replaceAll("%", ""));
                                if (p < 51) {
                                    //小于51%需要线下核验
                                    vo.setFcblFlag(BoolEnum.TRUE.getType());
                                }
                            }
                            vo.setSchoolId(eduAddressSchool.getOrgId());
                            vo.setAreaCode(eduAddressSchool.getAreaCode());
                            retList.add(vo);
                        }
                    }
                }
            }
        }

        return retList;
    }
    //获取户籍信息所属学校
    public List<HouseholdSchoolVO> getHouseholdSchool(EduStudentEnrollPre eduStudentEnrollPre, Map<String, EduOperationCacheDetailVO> operation){
        String idcard=eduStudentEnrollPre.getIdcard();
        QueryWrapper<EduHousehold> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(EduHousehold::getIdcard,idcard)
            .eq(EduHousehold::getStatus,BoolEnum.TRUE.getType())
            .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
            .eq(EduHousehold::getYear, eduStudentEnrollPre.getYear())
            .orderByDesc(EduHousehold::getQysj);
        List<EduHousehold> list =eduHouseholdService.list(queryWrapper);
        List<HouseholdSchoolVO> retList=new ArrayList<>();
        eduStudentEnrollPre.setFollowingFlag(BoolEnum.FALSE.getType());
        if (!CollectionUtils.isEmpty(list)){
            eduStudentEnrollPre.setFollowingFlag(BoolEnum.TRUE.getType());
            // 户籍启用是参数
            EduOperationCacheDetailVO hjOperation=operation.get("YW025");
            if(hjOperation.getEndTime()==null){
                throw new AppException("YW025未设置户籍截止时间");
            }
            Long householdEndTime=Long.parseLong(DateUtil.format(hjOperation.getEndTime(),"yyyyMMdd"));
            // 服务区房产启用是参数
            EduOperationCacheDetailVO hjfwOperation=operation.get("YW061");
            if (hjfwOperation.getEndTime() == null){
                throw new AppException("YW061未配置截至时间，请联系管理员进行配置");
            }
            Long householdEndTimeFw=Long.parseLong(DateUtil.format(hjfwOperation.getEndTime(),"yyyyMMdd"));
            for(EduHousehold eduHousehold:list){
                //获取地址和学校关联关系信息
                Boolean flag = true;
                String addressId=eduHousehold.getAddressId();
                String address= Convert.toDBC(eduHousehold.getAddress());
                if(StringUtils.isNotBlank(addressId)){
                    EduAddress eduAddress=eduAddressService.getById(addressId);
                    if(eduAddress==null){
                        flag=true;
                        addressId="";
                    }else {
                        if (!eduAddress.getAddressName().equals(address)) {
                            flag = true;
                            addressId = "";
                        } else {
                            flag = false;

                        }
                    }
                }
                if(flag){
                    QueryWrapper<EduAddress> eduAddressQueryWrapper=new QueryWrapper<>();
                    eduAddressQueryWrapper.lambda().eq(EduAddress::getAddressName,address);
                    List<EduAddress> addressList=eduAddressService.list(eduAddressQueryWrapper);
                    if(CollectionUtils.isEmpty(addressList)){
                        throw new AppException("地址池中未找到该户籍地址，请先联系管理员添加");
                    }else{
                        if(addressList.size()>1){
                            throw new AppException("同一户籍地址在地址池中找到多条数据，请联系管理员处理");
                        }
                        addressId=addressList.get(0).getAddressId();
                    }
                }
                SchoolDistrictQueryVO queryVO=new SchoolDistrictQueryVO();
                queryVO.setAddressId(addressId);
                queryVO.setSchoolCategory(eduStudentEnrollPre.getSchoolCategory());
                List<SchoolDistrictVO> schoolList= eduAddressSchoolService.getSchoolInfo(queryVO);

                if (!CollectionUtils.isEmpty(schoolList)){
                    for(SchoolDistrictVO eduAddressSchool:schoolList){
                        boolean conFlag = false;
                        for (HouseholdSchoolVO householdSchoolVO : retList) {
                            if (eduAddressSchool.getAddressId().equalsIgnoreCase(householdSchoolVO.getAddressId()) && householdSchoolVO.getSchoolId().equalsIgnoreCase(eduAddressSchool.getOrgId())) {
                                conFlag = true;
                            }
                        }
                        if (conFlag) {
                            continue;
                        }
                        //判断启用时间是否小于参数设置时间
                        boolean addFlag = true;
                        HouseholdSchoolVO vo= Convert.convert(HouseholdSchoolVO.class,eduHousehold);
                        vo.setOfflineFlag(BoolEnum.FALSE.getType());
                        vo.setServiceAreaFlag(eduAddressSchool.getServiceAreaFlag());
                        if(StringUtils.isBlank(vo.getServiceAreaFlag())){
                            vo.setServiceAreaFlag(BoolEnum.FALSE.getType());
                        }
                        if(StringUtils.isBlank(eduAddressSchool.getNativeFlag())){
                            vo.setNativeFlag(BoolEnum.FALSE.getType());
                        }else{
                            vo.setNativeFlag(eduAddressSchool.getNativeFlag());
                        }
                        if(!BoolEnum.TRUE.getType().equals(eduAddressSchool.getHouseholdEndTimeNo())){
                            if(StringUtils.isNotBlank(eduHousehold.getQysj())){
                                Long qysj= Long.parseLong(DateUtil.format(DateUtil.parse(eduHousehold.getQysj()),"yyyyMMdd"));
                                if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceAreaFlag())){
                                    //服务区
                                    if(eduAddressSchool.getHouseholdEndTimeFw()!=null){
                                        Long endTime=Long.parseLong(DateUtil.format(eduAddressSchool.getHouseholdEndTimeFw(),"yyyyMMdd"));
                                        if(qysj>endTime){
                                            addFlag=false;
                                        }
                                    }else{
                                        if(qysj>householdEndTimeFw){
                                            addFlag=false;
                                        }
                                    }
                                }else{
                                    //正学区
                                    if(eduAddressSchool.getHouseholdEndTime()!=null){

                                        Long endTime=Long.parseLong(DateUtil.format(eduAddressSchool.getHouseholdEndTime(),"yyyyMMdd"));
                                        if(qysj>endTime){
                                            addFlag=false;
                                        }
                                    }else{
                                        if(qysj>householdEndTime){
                                            addFlag=false;
                                        }
                                    }
                                }
                            }else{
                                if(eduHousehold.getUpdateTime()!=null){
                                    //更新时间在设置的截止时间之后的需要线下核验
                                    Long qysj= Long.parseLong(DateUtil.format(eduHousehold.getUpdateTime(),"yyyyMMdd"));

                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceAreaFlag())){
                                        //服务区
                                        if(eduAddressSchool.getHouseholdEndTimeFw()!=null){

                                            Long endTime=Long.parseLong(DateUtil.format(eduAddressSchool.getHouseholdEndTimeFw(),"yyyyMMdd"));
                                            if(qysj>endTime){
                                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                            }
                                        }else{
                                            if(qysj>householdEndTimeFw){
                                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                            }
                                        }
                                    }else{
                                        //正学区
                                        if(eduAddressSchool.getHouseholdEndTime()!=null){

                                            Long endTime=Long.parseLong(DateUtil.format(eduAddressSchool.getHouseholdEndTime(),"yyyyMMdd"));
                                            if(qysj>endTime){
                                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                            }
                                        }else{
                                            if(qysj>householdEndTime){
                                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                            }
                                        }
                                    }
                                }else{
                                    vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                }

                            }


                        }
                        if(addFlag){

                            vo.setSchoolId(eduAddressSchool.getOrgId());
                            vo.setAreaCode(eduAddressSchool.getAreaCode());
                            retList.add(vo);
                        }

                    }
                }
                break;
            }
        }
        return  retList;
    }

    //获取城区E
    private Map<String,String> getAppointSchool(EduStudentEnrollPre eduStudentEnrollPre){
        QueryWrapper<EduAppointStudent> appointStudentQueryWrapper=new QueryWrapper<>();
        appointStudentQueryWrapper.lambda().eq(EduAppointStudent::getYear,eduStudentEnrollPre.getYear())
                .eq(EduAppointStudent::getStatus, BoolEnum.TRUE.getType())
                .eq(EduAppointStudent::getIdcard,eduStudentEnrollPre.getIdcard());
        List<EduAppointStudent> eduAppointStudentList=eduAppointStudentService.list(appointStudentQueryWrapper);
        if(!CollectionUtils.isEmpty(eduAppointStudentList)){
            return eduAppointStudentList.stream().collect(Collectors.toMap(EduAppointStudent::getSchoolId, EduAppointStudent::getAppointStudentId,(k1,k2)->k1));
        }else{
            return null;
        }
    }
}
